/*
 * @Author: soso
 * @Date: 2022-02-16 14:11:33
 * @LastEditTime: 2022-03-09 10:56:26
 * @LastEditors: Please set LastEditors
 * @Description: 简略版httpserver
 * @FilePath: /gomeshsync/http/websvr.go
 */

package websvr

import (
	"log"
	"net/http"
	"os"
	"strconv"
)

func RunWebSvr(port int, dir string) {
	fi, e := os.Stat(dir)
	if os.IsNotExist(e) {
		panic(e)
	}
	if !fi.IsDir() {
		panic("Web root must be a directory")
	}

	fs := http.FileServer(http.Dir(dir))

	http.Handle("/", http.StripPrefix("/", fs))

	log.Printf("server will bind on %d \r\n", port)
	http.ListenAndServe(":"+strconv.Itoa(port), nil)
}
